|
Joined: Mar 2000
Posts: 4
Junior Member
|
Junior Member
Joined: Mar 2000
Posts: 4 |
Hi I have a script to log and track hits to my website. Here it is : #!/usr/bin/perl ################### Copyright ################################################## # This script is copyright by CGI-Center.com 1999. All rights reserved and so # # on. You are not allowed to resell or destribute this script in any way blah # # blah blah blah blah. # ################################################################################ # For help, suggestions or correction regarding this script please visit our # # CGI forum at http://www.cgi-center.cx/forum/ # ################################################################################ ################### Variables ################################################## $password = "guest"; # Your admin password. # # $image = "dot.gif"; # The URL of your graph-image. You are welcome to use your own image for this. # ################################################################################ # Define what statistics you want on the admin area. If you do not define them # # they will still be available by pressing a button on the admin area. # $last_refers = "yes"; # $top_refers = "yes"; # $last_visitors = "yes"; # $history = "yes"; # $top_pages = "yes"; # $search = "yes"; ################################################################################ # How big will you allow your log file to grow? Defined in kb. There is no # # limit to how big it may be but less than 1000 kb is advicable. # $max_log = "500"; ################################################################################ # No more editing is needed below this line # # # # # # # # ### # ############################### &getinput; print "Content-type: text/htmlnn"; $ip = $ENV{'REMOTE_ADDR'}; if ($INPUT{'password2'}) {&admin;} elsif ($ENV{'QUERY_STRING'} eq "login") {&login;} elsif ($INPUT{'login'}) {&admin;} elsif ($INPUT{'history'}) {&history;} elsif ($INPUT{'last_visitors'}) {&last_visitors;} elsif ($INPUT{'last_refers'}) {&last_refers;} elsif ($INPUT{'top_refers'}) {&top_refers;} elsif ($INPUT{'search'}) {&search;} elsif ($INPUT{'searchfor'}) {&searchfor;} elsif ($INPUT{'searchfor2'}) {&searchfor;} elsif ($INPUT{'top_pages'}) {&top_pages;} elsif ($INPUT{'reset'}) {&reset;} else {&count;} sub login { print " "; }
sub count { &get_date; ✓
unless (-e "date.txt") { open (DATE,">date.txt"); print DATE "$today"; close (DATE); } unless (-e "ips.txt") { open (IPS,">ips.txt"); close (IPS); }
open (DATE,"date.txt"); $oldday = ; close (DATE);
if (($oldday =~ /[0-9]/) && ($oldday < $today)) { open (DATE,">date.txt"); print DATE "$today"; close (DATE);
open (COUNT,"count.txt"); $count = ; close (COUNT); chop ($count) if ($count =~ /n$/);
open (COUNT,">count.txt"); close (COUNT);
open (HISTORY,"history.txt"); @history = ; close (HISTORY);
open (HISTORY,">history.txt"); print HISTORY "$yesterday|$countn"; foreach $line (@history) { print HISTORY "$line"; } close (HISTORY); } unless ($oldday =~ /[0-9]/) { open (DATE,">date.txt"); print DATE "$today"; close (DATE); } open (COUNT,"count.txt"); $count = ; close (COUNT);
chop ($count) if ($count =~ /n$/); $count++;
open (COUNT,">count.txt"); print COUNT "$count"; close (COUNT);
open (INFO,"info.txt"); @info = ; close (INFO);
open (INFO,">info.txt"); print INFO "$date|$clock|$ENV{'HTTP_REFERER'}|$ENV{'REMOTE_ADDR'}|$ENV{'REMOTE_HOST'}|$ENV{'HTTP_USER_AGENT'}|$ENV{'REQUEST_URI'}|n"; foreach $line (@info) { print INFO "$line"; } close (INFO); }
sub get_date { @days = ('Sunday','Monday','Tuesday','Wednesday', 'Thursday','Friday','Saturday'); @months = ('January','February','March','April','May','June','July', 'August','September','October','November','December');
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6]; $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec); $year += 1900;
if ($min < 10) { $min = "0"."$min"; }
$today = ($year*365)+($mon*30)+$mday; $hour = ($hour - $minus)+$plus; if ($hour < "0") { $hour = $hour+24; $today--; } if ($hour > "23") { $hour = $hour-24; $today++; } $clock = "$hour:$min"; $date = "@months[$mon] $mday";
$mday--; if ($mday <= "0") { $test = ($mon/2); $mday = 30; if ($test =~ /.|,/) { $mday = 31; } $mon--; } if ($mon < "0") { $mon = 12; } $yesterday = "@months[$mon] $mday"; }
sub check { unless (-e "history.txt") { open (HISTORY,">history.txt"); close (HISTORY); } unless (-e "count.txt") { open (COUNT,">count.txt"); close (COUNT); } unless (-e "info.txt") { open (COUNT,">info.txt"); close (COUNT); } }
sub reset { open (HISTORY,">history.txt"); close (HISTORY);
open (COUNT,">count.txt"); close (COUNT);
open (COUNT,">info.txt"); close (COUNT);
open (COUNT,">ips.txt"); close (COUNT);
open (COUNT,">date.txt"); close (COUNT);
&admin; }
sub admin { if ($INPUT{'password2'}) { $INPUT{'password'} = $INPUT{'password2'}; } &check_password; &get_date;
open (COUNT,"count.txt"); $count = ; close (COUNT);
open (HISTORY,"history.txt"); @history = ; close (HISTORY);
foreach $line (@history) { @stats = split/|/,$line; if (@stats[0] eq $yesterday) { $yesterdayhits = @stats[1]; } } unless ($yesterdayhits) { $yesterdayhits = " "; }
print "Mini logger admin area"; print "
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 87
Joined: December 2001
|
|
Forums63
Topics37,575
Posts293,931
Members13,824
|
Most Online6,139 Sep 21st, 2024
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|